package com.xcity.pomelo.response;

import com.xcity.db.entity.Land;
import com.xcity.db.entity.Player;
import com.xcity.game.land.LandBuyTemplate;
import com.xcity.game.land.LandTemplate;
import com.xcity.game.player.cache.PlayerCacheService;

import naga.x.App;
import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class BuyLandResponse extends Response {
	
	private LandInfo land;
	private long gold;
	private long totalGold;
	private int stone;
	
	public static class LandInfo {
		private int buildId;
		private String img;
		private int cost;
		private long income;
		private long maxIncome;
		private long money;
		private String name;
		private long price;
		private byte buyType;
		private Owner owner;
		public int getBuildId() {
			return buildId;
		}
		public void setBuildId(int buildId) {
			this.buildId = buildId;
		}
		public String getImg() {
			return img;
		}
		public void setImg(String img) {
			this.img = img;
		}
		public int getCost() {
			return cost;
		}
		public void setCost(int cost) {
			this.cost = cost;
		}
		public long getIncome() {
			return income;
		}
		public void setIncome(long income) {
			this.income = income;
		}
		public long getMaxIncome() {
			return maxIncome;
		}
		public void setMaxIncome(long maxIncome) {
			this.maxIncome = maxIncome;
		}
		public long getMoney() {
			return money;
		}
		public void setMoney(long money) {
			this.money = money;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public long getPrice() {
			return price;
		}
		public void setPrice(long price) {
			this.price = price;
		}
		public byte getBuyType() {
			return buyType;
		}
		public void setBuyType(byte buyType) {
			this.buyType = buyType;
		}
		public Owner getOwner() {
			return owner;
		}
		public void setOwner(Owner owner) {
			this.owner = owner;
		}
	}
	
	public static class Owner {
		private long ownerId;
		private String ownerName;
		private String ownerHead;
		public long getOwnerId() {
			return ownerId;
		}
		public void setOwnerId(long ownerId) {
			this.ownerId = ownerId;
		}
		public String getOwnerName() {
			return ownerName;
		}
		public void setOwnerName(String ownerName) {
			this.ownerName = ownerName;
		}
		public String getOwnerHead() {
			return ownerHead;
		}
		public void setOwnerHead(String ownerHead) {
			this.ownerHead = ownerHead;
		}
	}
	
	public BuyLandResponse(int serial, Land land, Player player) {
		super(serial);
		LandTemplate temp = land.getTemplate();
		LandBuyTemplate buyTemp = temp.getBuyTemplate(land.getLevel());
		this.land = new LandInfo();
		this.land.buildId = land.getId();
		this.land.img = temp.getImage();
		this.land.cost = 0;
		this.land.income = buyTemp.getIncome();
		this.land.maxIncome = buyTemp.getMaxIncome();
		this.land.money = land.calcMoney();
		this.land.name = temp.getName();
		this.land.price = buyTemp.getCost();
		this.land.buyType = temp.getCostType();
		this.land.owner = new Owner();
		this.land.owner.ownerId = land.getOwnerId();
		Player actor = App.getApp().getServiceManager().get(PlayerCacheService.class).find(land.getOwnerId());
		this.land.owner.ownerName = actor.getName();
		this.land.owner.ownerHead = actor.getIcon();
		
		this.gold = player.getGold();
		this.totalGold = player.getFixedAssets();
		this.stone = player.getStone();
	}

	public LandInfo getLand() {
		return land;
	}

	public void setLand(LandInfo land) {
		this.land = land;
	}

	public long getGold() {
		return gold;
	}

	public void setGold(long gold) {
		this.gold = gold;
	}

	public long getTotalGold() {
		return totalGold;
	}

	public void setTotalGold(long totalGold) {
		this.totalGold = totalGold;
	}

	public int getStone() {
		return stone;
	}

	public void setStone(int stone) {
		this.stone = stone;
	}

}
